package action;

import dao.UserDao;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import po.User;

@WebServlet(urlPatterns = "/user/action/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname = req.getParameter("uname");
        String upwd = req.getParameter("upwd");
        String email = req.getParameter("email");
        String phone = req.getParameter("phone");
        User user = new User();
        user.setRole(0);
        user.setUname(uname);
        user.setUpwd(upwd);
        user.setEmail(email);
        user.setPhone(phone);
        UserDao userDao = new UserDao();
        String result = "../page/register.jsp";
        int row = userDao.insert(user);
        if (row > 0) {
            result = "../page/login.jsp";
        }

        req.getRequestDispatcher(result).forward(req, resp);
    }
}
